#include "mywidget.h"
TcpServerWidget::TcpServerWidget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(300,300);
    qButton1.setText(QString("CloseButton"));
    qButton1.setParent(this);
    qButton1.show();
    qButton1.move(100,100);


    qButton2 = new QPushButton(this);
    this->setWindowTitle("主窗口");
    qButton2->setText("切换到子窗口");

    subWidget = new SubWidget();

    connect(&qButton1,&QPushButton::pressed,this,&QPushButton::close);
    connect(qButton2,&QPushButton::released,this,&TcpServerWidget::hideSubWind);

    //QT5
    //    void (SubWidget::*sign)()=&SubWidget::mysign;
    //    void (SubWidget::*signParam)(int a,QString qString)=&SubWidget::mysign;

    //    connect(subWidget,sign,this,&Widget::handleSubWinSign);
    //    connect(subWidget,signParam,this,&Widget::handleSubWinSignWithParam);

    //QT4不做编译检查
    connect(subWidget,SIGNAL(mysign()),this,SLOT(handleSubWinSign()));
    connect(subWidget,SIGNAL(mysign(int,QString)),this,SLOT(handleSubWinSignWithParam(int,QString)));

    QPushButton* but1 = new QPushButton(this);
    but1->setText("Hello");
    but1->move(120,150);
    int a  = 100;
    connect(but1,&QPushButton::clicked,
            [=]()mutable
            //[=]：表示传递所有参数
            //mutable：表示外部参数可修改
    {
        qDebug()<<"123456";
        but1->setText("changeText");
        a=11;
    });

}
void  TcpServerWidget::hideSubWind()
{
    subWidget->show();
    this->hide();
}
TcpServerWidget::~TcpServerWidget()
{

}
void  TcpServerWidget::handleSubWinSign()
{
    subWidget->hide();
    this->show();
}
void  TcpServerWidget::handleSubWinSignWithParam(int a,QString qString)
{
    qDebug() << a << qString;
}
